package cn.com.duiba.millionaire.center.biz.dao.impl;

import cn.com.duiba.millionaire.center.biz.constants.DatabaseSchema;
import cn.com.duiba.millionaire.center.biz.dao.BaseDao;
import cn.com.duiba.millionaire.center.biz.dao.MillionaireMtAcRelationDao;
import cn.com.duiba.millionaire.center.biz.entity.MillionaireMtAcRelationEntity;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sty on 1/18/18.
 */
@Repository
public class MillionaireMtAcRelationDaoImpl extends BaseDao implements MillionaireMtAcRelationDao {
    @Override
    public MillionaireMtAcRelationEntity insert(MillionaireMtAcRelationEntity millionaireMtAcRelationEntity) {
        insert("insert", millionaireMtAcRelationEntity);
        return millionaireMtAcRelationEntity;
    }

    @Override
    public List<MillionaireMtAcRelationEntity> findByMainMeetingId(Long mainMeetingId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("mainMeetingId", mainMeetingId);
        return selectList("findByMainMeetingId", params);
    }

    @Override
    public List<Long> findActivityIdsByMeetingId(Long mainMeetingId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("mainMeetingId",mainMeetingId);
        return selectList("findActivityIdsByMeetingId",params);
    }

    @Override
    public int deleteByIds(List<Long> ids) {
        if(CollectionUtils.isEmpty(ids)){
            return 0;
        }
        Map<String, Object> params = Maps.newHashMap();
        params.put("ids", ids);
        return update("deleteByIds", params);
    }

    @Override
    public int deleteByMainMeetingId(Long mainMeetingId) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("mainMeetingId", mainMeetingId);
        return update("deleteByMainMeetingId", params);
    }

    @Override
    public int batchInsert(Long mainMeetingId, List<Long> activityIds) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("meetingId", mainMeetingId);
        params.put("activityIds", activityIds);
        return insert("batchInsert", params);
    }

    @Override
    public List<MillionaireMtAcRelationEntity> findByInActivityIds(List<Long> activityIds) {
        return selectList("findByInActivityIds",activityIds);
    }

    @Override
    public List<Long> findAllActivityIds() {
        return selectList("findAllActivityIds",new HashMap<>());
    }

    @Override
    protected DatabaseSchema chooseSchema() {
        return DatabaseSchema.MILLIONAIRE_CONFIG;
    }
}
